package com.xhji.spider.controller;

import com.xhji.web.config.redis.CacheExpire;
import com.xhji.web.config.redis.RedisUtil;
import com.xhji.web.config.redis.TimeType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private RedisUtil redisUtil;

    @RequestMapping("/getUser")
    @Cacheable(value="user-key", key = "123")
    public String getUser() {
        System.out.println("无缓存的时候调用");
        return "测试redis缓存";
    }

    @Cacheable(value="user", key = "222")
    @CacheExpire(value = 2, type = TimeType.HOURS)
    @RequestMapping("/user")
    public String user(){
        System.out.println("1111");
        redisUtil.set("哈哈", "哈哈哈哈哈");
        redisUtil.hset("这是","一个","测试");
        return  "123";
    }

    @Value("${com.xhji.title}")
    private String title;

    @RequestMapping("/user2")
    public String user2(){
        System.out.println(title);
        return  "123";
    }
}
